package bma.common.netty.handler;

import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

/**
 * 监控上行消息和异常是否都被处理，否则进行警告提示
 * 
 * @author "guanzhong"
 * 
 */
public class ChannelHandlerMissWarn extends SimpleChannelUpstreamHandler {

	final org.slf4j.Logger log = org.slf4j.LoggerFactory
			.getLogger(ChannelHandlerMissWarn.class);

	@Override
	public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
			throws Exception {
		if (log.isWarnEnabled()) {
			log.warn("{} message miss : {}", ctx.getChannel(), e.getMessage());
		}
		super.messageReceived(ctx, e);
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
			throws Exception {
		if (log.isWarnEnabled()) {
			log.warn(ctx.getChannel() + " exception miss", e.getCause());
		}
		super.exceptionCaught(ctx, e);
	}
}
